package com.yy.bolg.controller.customer;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yy.bolg.constant.ResultCode;
import com.yy.bolg.entity.CustomerBean;
import com.yy.bolg.entity.ElectricianBean;
import com.yy.bolg.request.CustomerRequest;
import com.yy.bolg.request.ElectricianRequest;
import com.yy.bolg.request.statistics.admin.CustomerRegionStatisticsRequest;
import com.yy.bolg.resp.CustomerResp;
import com.yy.bolg.resp.ElectricianResp;
import com.yy.bolg.resp.statistics.admin.CustomerRegionStatisticsResp;
import com.yy.bolg.service.CustomerService;
import com.yy.bolg.service.ElectricianService;
import com.yy.bolg.util.ChongQingRegionUtil;
import com.yy.bolg.util.CodeGenerateUtil;
import com.yy.bolg.util.RespenseJsonTransformationUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * 客户控制器
 * @author enmaoFu
 * @date 2024-11-02
 * RequestMapping("/customer") 是说明这个类的访问地址是 /customer
 */
@Api(tags = {"客户（单位）"})
@Controller
@RequestMapping(value = "/customer")
public class CustomerController {

    @Autowired
    private CustomerService service;// 自动载入Service对象

    /**
     * 登录
     * 服务器访问路径：http://localhost:8080/bolg/customer/signIn
     * 本地访问路径：http://localhost:8111/customer/signIn
     * 参数：
     * {"customerUserPhone":"1234567890","customerUserPwd":"123456"}
     */
    @ApiOperation(value = "登录", notes = "参数：{\"customerUserPhone\":\"1234567890\",\"customerUserPwd\":\"123456\"}")
    @RequestMapping(value = "/signIn",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String signIn(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerUserPhone(request.getCustomerUserPhone());
        customerBean.setPsCustomerUserPwd(request.getCustomerUserPwd());
        customerBean.setPsCustomerLoginState(1);

        try {
            String code = service.signIn(customerBean);

            Map map = new HashMap();
            map.put("data", code);

            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "登录成功", map);
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 退出
     * 服务器访问路径：http://localhost:8080/bolg/customer/signOut
     * 本地访问路径：http://localhost:8111/customer/signOut
     * 参数：
     * {"customerCode":"CUS20241102102456"}
     */
    @ApiOperation(value = "退出", notes = "参数：{\"customerCode\":\"CUS20241102102456\"}")
    @RequestMapping(value = "/signOut",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String signOut(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());
        customerBean.setPsCustomerLoginState(2);

        try {
            service.signOut(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "退出成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 注册
     * 服务器访问路径：http://localhost:8080/bolg/customer/register
     * 本地访问路径：http://localhost:8111/customer/register
     * 参数：
     * {"customerUserHead":"","customerUserName":"张三","customerUserPhone":"1234567890","customerUserPwd":"123456","customerUserPosition":"","customerName":"重庆市场监督管理局","customerProvince":"重庆市","customerCity":"重庆市","customerRegion":"九龙坡区","customerAddress":"龙腾大道10号","customerLongitude":29.123,"customerLatitude":103.123,"customerCategory":1,"customerLicense":"","customerEmergencyUserName":"","customerEmergencyUserPhone":""}
     */
    @ApiOperation(value = "注册", notes = "参数：{\"customerUserHead\":\"\",\"customerUserName\":\"张三\",\"customerUserPhone\":\"1234567890\",\"customerUserPwd\":\"123456\",\"customerUserPosition\":\"\",\"customerName\":\"重庆市场监督管理局\",\"customerProvince\":\"重庆市\",\"customerCity\":\"重庆市\",\"customerRegion\":\"九龙坡区\",\"customerAddress\":\"龙腾大道10号\",\"customerLongitude\":29.123,\"customerLatitude\":103.123,\"customerCategory\":1,\"customerLicense\":\"\",\"customerEmergencyUserName\":\"\",\"customerEmergencyUserPhone\":\"\"}")
    @RequestMapping(value = "/register",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String register(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(CodeGenerateUtil.getCustomerCode());
        if(StringUtils.isEmpty(request.getCustomerUserHead())){
            customerBean.setPsCustomerUserHead("https://www.cqwuyang.cn/images/defaultHead.png");
        }else{
            customerBean.setPsCustomerUserHead(request.getCustomerUserHead());
        }
        customerBean.setPsCustomerUserName(request.getCustomerUserName());
        customerBean.setPsCustomerUserPhone(request.getCustomerUserPhone());
        customerBean.setPsCustomerUserPwd(request.getCustomerUserPwd());
        customerBean.setPsCustomerUserPosition(request.getCustomerUserPosition());
        customerBean.setPsCustomerName(request.getCustomerName());
        customerBean.setPsCustomerProvince(request.getCustomerProvince());
        customerBean.setPsCustomerCity(request.getCustomerCity());
        customerBean.setPsCustomerRegion(request.getCustomerRegion());
        customerBean.setPsCustomerAddress(request.getCustomerAddress());
        customerBean.setPsCustomerLongitude(request.getCustomerLongitude());
        customerBean.setPsCustomerLatitude(request.getCustomerLatitude());
        customerBean.setPsCustomerCategory(request.getCustomerCategory());
        customerBean.setPsCustomerLicense(request.getCustomerLicense());
        customerBean.setPsCustomerEmergencyUserName(request.getCustomerEmergencyUserName());
        customerBean.setPsCustomerEmergencyUserPhone(request.getCustomerEmergencyUserPhone());
        customerBean.setPsCustomerState(1);
        customerBean.setPsCustomerLoginState(2);

        try {
            service.add(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "注册成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 修改用户信息
     * 服务器访问路径：http://localhost:8080/bolg/customer/upCustomerUserInfo
     * 本地访问路径：http://localhost:8111/customer/upCustomerUserInfo
     * 参数：
     * {"customerUserPhone":"12345678901","customerUserName":"111","customerUserPwd":"111","customerUserHead":"111","customerUserPosition":"111","generalPhone":"12345678901"}
     */
    @ApiOperation(value = "修改用户信息", notes = "参数：{\"customerUserPhone\":\"12345678901\",\"customerUserName\":\"111\",\"customerUserPwd\":\"111\",\"customerUserHead\":\"111\",\"customerUserPosition\":\"111\",\"generalPhone\":\"12345678901\"}")
    @RequestMapping(value = "/upCustomerUserInfo",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String upCustomerUserInfo(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerUserPhone(request.getCustomerUserPhone());
        customerBean.setPsCustomerUserName(request.getCustomerUserName());
        customerBean.setPsCustomerUserPwd(request.getCustomerUserPwd());
        customerBean.setPsCustomerUserHead(request.getCustomerUserHead());
        customerBean.setPsCustomerUserPosition(request.getCustomerUserPosition());
        customerBean.setGeneralPhone(request.getGeneralPhone());

        try {
            service.upCustomerUserInfo(customerBean);

            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "修改成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 修改紧急联人信息
     * 服务器访问路径：http://localhost:8080/bolg/customer/upCustomerEmergencyUserInfo
     * 本地访问路径：http://localhost:8111/customer/upCustomerEmergencyUserInfo
     * 参数：
     * {"customerEmergencyUserPhone":"18502371600","customerEmergencyUserName":"江来11111","generalPhone":"111"}
     */
    @ApiOperation(value = "修改紧急联人信息", notes = "参数：{\"customerEmergencyUserPhone\":\"18502371600\",\"customerEmergencyUserName\":\"江来11111\",\"generalPhone\":\"111\"}")
    @RequestMapping(value = "/upCustomerEmergencyUserInfo",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String upCustomerEmergencyUserInfo(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerEmergencyUserPhone(request.getCustomerEmergencyUserPhone());
        customerBean.setPsCustomerEmergencyUserName(request.getCustomerEmergencyUserName());
        customerBean.setGeneralPhone(request.getGeneralPhone());

        try {
            service.upCustomerEmergencyUserInfo(customerBean);

            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "修改成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 修改单位信息
     * 服务器访问路径：http://localhost:8080/bolg/customer/upCustomerInfo
     * 本地访问路径：http://localhost:8111/customer/upCustomerInfo
     * 参数：
     * {"customerCode":"CUS20241219000133","customerName":"单位名称","customerProvince":"省","customerCity":"市","customerRegion":"区","customerAddress":"详细地址","customerLongitude":0.0,"customerLatitude":0.0,"customerCategory":2,"customerLicense":"营业执照"}
     */
    @ApiOperation(value = "修改单位信息", notes = "参数：{\"customerCode\":\"CUS20241219000133\",\"customerName\":\"单位名称\",\"customerProvince\":\"省\",\"customerCity\":\"市\",\"customerRegion\":\"区\",\"customerAddress\":\"详细地址\",\"customerLongitude\":0.0,\"customerLatitude\":0.0,\"customerCategory\":2,\"customerLicense\":\"营业执照\"}")
    @RequestMapping(value = "/upCustomerInfo",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String upCustomerInfo(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());
        customerBean.setPsCustomerName(request.getCustomerName());
        customerBean.setPsCustomerProvince(request.getCustomerProvince());
        customerBean.setPsCustomerCity(request.getCustomerCity());
        customerBean.setPsCustomerRegion(request.getCustomerRegion());
        customerBean.setPsCustomerAddress(request.getCustomerAddress());
        customerBean.setPsCustomerLatitude(request.getCustomerLatitude());
        customerBean.setPsCustomerLongitude(request.getCustomerLongitude());
        customerBean.setPsCustomerCategory(request.getCustomerCategory());
        customerBean.setPsCustomerLicense(request.getCustomerLicense());

        try {
            service.upCustomerInfo(customerBean);

            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "修改成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 删除客户
     * 服务器访问路径：http://localhost:8080/bolg/customer/delete
     * 本地访问路径：http://localhost:8111/customer/delete
     * 参数：
     * {"customerCode":"CUS20241102102456"}
     */
    @ApiOperation(value = "删除客户（单位）", notes = "参数：{\"customerCode\":\"CUS20241102102456\"}")
    @RequestMapping(value = "/delete",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String delete(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());

        try {
            service.del(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "删除成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 客户状态更改
     * 服务器访问路径：http://localhost:8080/bolg/customer/stateUp
     * 本地访问路径：http://localhost:8111/customer/stateUp
     * 参数：
     * {"customerCode":"CUS20241102102456","customerState": 1,"hikUnitId":""}
     */
    @ApiOperation(value = "客户状态更改", notes = "参数：{\"customerCode\":\"CUS20241102102456\",\"customerState\": 1,\"hikUnitId\":\"\"}")
    @RequestMapping(value = "/stateUp",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String stateUp(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());
        customerBean.setPsCustomerState(request.getCustomerState());
        customerBean.setPsCustomerUnitid(request.getHikUnitId());

        try {
            service.upState(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "操作成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 绑定海康单位ID
     * 服务器访问路径：http://localhost:8080/bolg/customer/bindHikUnitId
     * 本地访问路径：http://localhost:8111/customer/bindHikUnitId
     * 参数：
     * {"customerCode":"CUS20241102102456","hikUnitId": "1065993914997006336"}
     */
    @ApiOperation(value = "绑定海康单位ID", notes = "参数：{\"customerCode\":\"CUS20241102102456\",\"hikUnitId\": \"1065993914997006336\"}")
    @RequestMapping(value = "/bindHikUnitId",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String bindHikUnitId(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());
        customerBean.setPsCustomerUnitid(request.getHikUnitId());

        try {
            service.bindHik(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "绑定成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 修改客户业务运营信息
     * 服务器访问路径：http://localhost:8080/bolg/customer/operateInfoUp
     * 本地访问路径：http://localhost:8111/customer/operateInfoUp
     * 参数：
     * {"customerCode":"CUS20241102102456","customerSaleName":"销售员1号","customerSalePhone":"11111111111","customerSaleState":2,"customerSaleContractFile":"https://bbs.wps.cn/cms/RW8tMm6k.html","customerTaxpayerNumber":"330203DK00917","customerTaxpayerAddress":"重庆市九龙坡区龙腾大道30号","customerTaxpayerPhone":"23456789876","customerTaxpayerBankName":"招商银行重庆高新区支行","customerTaxpayerBankCode":"6214832319625013"}
     */
    @ApiOperation(value = "修改客户业务运营信息", notes = "参数：{\"customerCode\":\"CUS20241102102456\",\"customerSaleName\":\"销售员1号\",\"customerSalePhone\":\"11111111111\",\"customerSaleState\":2,\"customerSaleContractFile\":\"https://bbs.wps.cn/cms/RW8tMm6k.html\",\"customerTaxpayerNumber\":\"330203DK00917\",\"customerTaxpayerAddress\":\"重庆市九龙坡区龙腾大道30号\",\"customerTaxpayerPhone\":\"23456789876\",\"customerTaxpayerBankName\":\"招商银行重庆高新区支行\",\"customerTaxpayerBankCode\":\"6214832319625013\"}")
    @RequestMapping(value = "/operateInfoUp",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String operateInfoUp(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());
        customerBean.setPsCustomerSaleName(request.getCustomerSaleName());
        customerBean.setPsCustomerSalePhone(request.getCustomerSalePhone());
        customerBean.setPsCustomerSaleState(request.getCustomerSaleState());
        customerBean.setPsCustomerSaleContractFile(request.getCustomerSaleContractFile());
        customerBean.setPsCustomerTaxpayerNumber(request.getCustomerTaxpayerNumber());
        customerBean.setPsCustomerTaxpayerAddress(request.getCustomerTaxpayerAddress());
        customerBean.setPsCustomerTaxpayerPhone(request.getCustomerTaxpayerPhone());
        customerBean.setPsCustomerTaxpayerBankName(request.getCustomerTaxpayerBankName());
        customerBean.setPsCustomerTaxpayerBankCode(request.getCustomerTaxpayerBankCode());

        try {
            service.up(customerBean);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "操作成功", new HashMap());
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 获取客户信息
     * 服务器访问路径：http://localhost:8080/bolg/customer/getCustomerInfo
     * 本地访问路径：http://localhost:8111/customer/getCustomerInfo
     * 参数：
     * {"customerCode":"CUS20241102102456"}
     */
    @ApiOperation(value = "获取客户信息", notes = "参数：{\"customerCode\":\"CUS20241102102456\"}", response = CustomerResp.class)
    @RequestMapping(value = "/getCustomerInfo",method = RequestMethod.POST, produces="text/html;charset=UTF-8")
    @ResponseBody
    public String getCustomerInfo(@RequestBody CustomerRequest request){
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerCode(request.getCustomerCode());

        try {
            CustomerBean returnBean = service.findOneByCode(customerBean);
            if (null != returnBean) {
                CustomerResp resp = new CustomerResp();
                resp.setCustomerCode(returnBean.getPsCustomerCode());
                resp.setCustomerUserHead(returnBean.getPsCustomerUserHead());
                resp.setCustomerUserName(returnBean.getPsCustomerUserName());
                resp.setCustomerUserPhone(returnBean.getPsCustomerUserPhone());
                resp.setCustomerUserPwd(returnBean.getPsCustomerUserPwd());
                resp.setCustomerUserPosition(returnBean.getPsCustomerUserPosition());
                resp.setCustomerName(returnBean.getPsCustomerName());
                resp.setCustomerProvince(returnBean.getPsCustomerProvince());
                resp.setCustomerCity(returnBean.getPsCustomerCity());
                resp.setCustomerRegion(returnBean.getPsCustomerRegion());
                resp.setCustomerAddress(returnBean.getPsCustomerAddress());
                resp.setCustomerLongitude(returnBean.getPsCustomerLongitude());
                resp.setCustomerLatitude(returnBean.getPsCustomerLatitude());
                resp.setCustomerCategory(returnBean.getPsCustomerCategory());
                resp.setCustomerLicense(returnBean.getPsCustomerLicense());
                resp.setCustomerEmergencyUserName(returnBean.getPsCustomerEmergencyUserName());
                resp.setCustomerEmergencyUserPhone(returnBean.getPsCustomerEmergencyUserPhone());
                resp.setCustomerState(returnBean.getPsCustomerState());
                resp.setCustomerSaleName(returnBean.getPsCustomerSaleName());
                resp.setCustomerSalePhone(returnBean.getPsCustomerSalePhone());
                resp.setCustomerSaleState(returnBean.getPsCustomerSaleState());
                resp.setCustomerSaleContractFile(returnBean.getPsCustomerSaleContractFile());
                resp.setCustomerTaxpayerNumber(returnBean.getPsCustomerTaxpayerNumber());
                resp.setCustomerTaxpayerAddress(returnBean.getPsCustomerTaxpayerAddress());
                resp.setCustomerTaxpayerPhone(returnBean.getPsCustomerTaxpayerPhone());
                resp.setCustomerTaxpayerBankName(returnBean.getPsCustomerTaxpayerBankName());
                resp.setCustomerTaxpayerBankCode(returnBean.getPsCustomerTaxpayerBankCode());
                resp.setCustomerLoginState(returnBean.getPsCustomerLoginState());
                resp.setCustomerUnitid(returnBean.getPsCustomerUnitid());

                Map map = new HashMap();
                map.put("data", resp);
                result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "获取信息成功", map);
            } else {
                result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL,"暂无数据",new HashMap());
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL,e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 查询（分页）客户-支持区域、类型、名称条件查询-条件字段可空（分页相关除外）
     * 服务器访问路径：http://localhost:8080/bolg/customer/findAllByCondition
     * 本地访问路径：http://localhost:8111/customer/findAllByCondition
     * 参数：
     * {"customerRegion":"九龙坡","customerCategory":1,"customerName":"市场", "customerState":-1, "hikUnitId":"1109450856339275777", "pageNum":"1","pageSize":"5"}
     */
    @ApiOperation(value = "查询（分页）客户-支持区域、类型、名称条件查询-条件字段可空（分页相关除外）", notes = "参数：{\"customerRegion\":\"九龙坡\",\"customerCategory\":1,\"customerName\":\"市场\", \"customerState\":-1, \"hikUnitId\":\"1109450856339275777\", \"pageNum\":\"1\",\"pageSize\":\"5\"}", response = CustomerResp.class)
    @RequestMapping(value = "/findAllByCondition",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String findAllByCondition(@RequestBody CustomerRequest request){
        Page pageInfo = PageHelper.startPage(request.getPageNum(), request.getPageSize());
        String result;

        CustomerBean customerBean = new CustomerBean();
        customerBean.setPsCustomerRegion(request.getCustomerRegion());
        customerBean.setPsCustomerCategory(request.getCustomerCategory());
        customerBean.setPsCustomerName(request.getCustomerName());
        customerBean.setPsCustomerState(request.getCustomerState());
        customerBean.setPsCustomerUnitid(request.getHikUnitId());

        try {
            List<CustomerResp> respList = new ArrayList<>();
            for(CustomerBean returnBean : service.findAllByCondition(customerBean)){
                CustomerResp resp = new CustomerResp();
                resp.setCustomerCode(returnBean.getPsCustomerCode());
                resp.setCustomerUserHead(returnBean.getPsCustomerUserHead());
                resp.setCustomerUserName(returnBean.getPsCustomerUserName());
                resp.setCustomerUserPhone(returnBean.getPsCustomerUserPhone());
                resp.setCustomerUserPwd(returnBean.getPsCustomerUserPwd());
                resp.setCustomerUserPosition(returnBean.getPsCustomerUserPosition());
                resp.setCustomerName(returnBean.getPsCustomerName());
                resp.setCustomerProvince(returnBean.getPsCustomerProvince());
                resp.setCustomerCity(returnBean.getPsCustomerCity());
                resp.setCustomerRegion(returnBean.getPsCustomerRegion());
                resp.setCustomerAddress(returnBean.getPsCustomerAddress());
                resp.setCustomerLongitude(returnBean.getPsCustomerLongitude());
                resp.setCustomerLatitude(returnBean.getPsCustomerLatitude());
                resp.setCustomerCategory(returnBean.getPsCustomerCategory());
                resp.setCustomerLicense(returnBean.getPsCustomerLicense());
                resp.setCustomerEmergencyUserName(returnBean.getPsCustomerEmergencyUserName());
                resp.setCustomerEmergencyUserPhone(returnBean.getPsCustomerEmergencyUserPhone());
                resp.setCustomerState(returnBean.getPsCustomerState());
                resp.setCustomerSaleName(returnBean.getPsCustomerSaleName());
                resp.setCustomerSalePhone(returnBean.getPsCustomerSalePhone());
                resp.setCustomerSaleState(returnBean.getPsCustomerSaleState());
                resp.setCustomerSaleContractFile(returnBean.getPsCustomerSaleContractFile());
                resp.setCustomerTaxpayerNumber(returnBean.getPsCustomerTaxpayerNumber());
                resp.setCustomerTaxpayerAddress(returnBean.getPsCustomerTaxpayerAddress());
                resp.setCustomerTaxpayerPhone(returnBean.getPsCustomerTaxpayerPhone());
                resp.setCustomerTaxpayerBankName(returnBean.getPsCustomerTaxpayerBankName());
                resp.setCustomerTaxpayerBankCode(returnBean.getPsCustomerTaxpayerBankCode());
                resp.setCustomerLoginState(returnBean.getPsCustomerLoginState());
                resp.setCustomerUnitid(returnBean.getPsCustomerUnitid());
                respList.add(resp);
            }

            Map map = new HashMap();
            map.put("pageInfo", pageInfo);
            map.put("rows", respList);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "查询成功", map);
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }

    /**
     * 后台系统数据统计-单位地区分布
     * 服务器访问路径：http://localhost:8080/bolg/customer/getCustomerStatisticsRegion
     * 本地访问路径：http://localhost:8111/customer/getCustomerStatisticsRegion
     */
    @ApiOperation(value = "后台系统数据统计-单位地区分布", response = CustomerRegionStatisticsResp.class)
    @RequestMapping(value = "/getCustomerStatisticsRegion",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String getCustomerStatisticsRegion(@RequestBody CustomerRegionStatisticsRequest request){
        String result;
        try {
            List<CustomerBean> returnAllBeans = service.findAll();
            List<String> regionNoUnits = ChongQingRegionUtil.getChongQingRegionNoUnit();

            List<CustomerRegionStatisticsResp> customerRegionStatisticsResps = new ArrayList<>();

            if(null != returnAllBeans && returnAllBeans.size() != 0){
                for(String region: regionNoUnits){
                    CustomerRegionStatisticsResp itemResp = new CustomerRegionStatisticsResp();
                    int num = 0;
                    for(CustomerBean cb: returnAllBeans){
                        if(cb.getPsCustomerRegion().contains(region)){
                            num += 1;
                        }
                    }
                    itemResp.setRegionStr(region);
                    itemResp.setNum(num);
                    customerRegionStatisticsResps.add(itemResp);
                }
            }

            Map map = new HashMap();
            if(request.getRemoveZero() == 0){
                Iterator<CustomerRegionStatisticsResp> crsResps = customerRegionStatisticsResps.iterator();
                while(crsResps.hasNext()){
                    CustomerRegionStatisticsResp woResp = crsResps.next();
                    if (woResp.getNum() == 0) {
                        crsResps.remove();
                    }
                }
            }
            map.put("data", customerRegionStatisticsResps);
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_SUCCESS, "查询成功", map);
        } catch (Exception e) {
            e.printStackTrace();
            result = RespenseJsonTransformationUtil.jsonStr(ResultCode.CODE_FAIL, e.getMessage(),new HashMap());
        }
        return result;
    }
}
